package com.yanqu.road.server.gameplayer.module.activity.summergames;

import com.yanqu.road.dao.impl.activity.summergames.SummerGamesUserDataDaoImpl;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.summergames.*;
import com.yanqu.road.entity.activity.summergames.config.SummerGamesConvertInfo;
import com.yanqu.road.entity.activity.summergames.config.SummerGamesLotteryInfo;
import com.yanqu.road.entity.activity.summergames.config.SummerGamesProjectInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.log.summergames.LogSummerGamesEntry;
import com.yanqu.road.logic.helper.RandomWeightConfigHelper;
import com.yanqu.road.pb.activity.SummerGamesProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.summergames.SummerGamesActivityMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.*;

public class SummerGamesModule extends GeneralModule {

    private SummerGamesUserData userData;

    private Random random = new Random();

    public SummerGamesModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        ActivityInfo activityInfo = SummerGamesActivityMgr.getActivityInfo();
        if(ActivityMgr.activityInShowTime(activityInfo)) {
            userData = new SummerGamesUserDataDaoImpl().getSummerGamesUserData(activityInfo.getActivityId(), player.getUserId());
        }
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        if(userData != null){
            if(userData.isInsertOption()){
                new SummerGamesUserDataDaoImpl().add(userData);
            } else if (userData.isUpdateOption()) {
                new SummerGamesUserDataDaoImpl().update(userData);
            }
        }
        return true;
    }

    @Override
    public void afterLogin() {
        activityReload();
    }

    public void activityReload() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.SummerGamesActivity.getValue())) {
            return;
        }

        SummerGamesConfig summerGamesConfig = SummerGamesActivityMgr.getSummerGamesConfig();

        if(summerGamesConfig == null || !ActivityMgr.activityInShowTime(summerGamesConfig.getActivityInfo())){
            return;
        }

        syncConfig(summerGamesConfig);

        initUserData(summerGamesConfig);

        if(!resetOneDay()) {
            syncUserData();
        }

        syncExchangeTip(userData);
    }

    private void syncConfig(SummerGamesConfig summerGamesConfig) {

        SummerGamesProto.SummerGamesConfigSyncMsg.Builder clientMsg = SummerGamesProto.SummerGamesConfigSyncMsg.newBuilder();

        for (SummerGamesLotteryInfo info : summerGamesConfig.getLotteryInfoList()) {
            SummerGamesProto.SummerGamesLotteryTemp.Builder builder = SummerGamesProto.SummerGamesLotteryTemp.newBuilder();
            builder.setId(info.getId());
            builder.setMedalsType(info.getMedalsType());
            builder.setScore(info.getScore());
            builder.setWeight(info.getWeight());
            builder.setName(ServerLanguageMgr.getContent(info.getName(), player.getLanguage()));
            clientMsg.addLottery(builder);
        }

        for (SummerGamesProjectInfo projectInfo : summerGamesConfig.getProjectInfoList()) {
            SummerGamesProto.SummerGamesProjectTemp.Builder builder = SummerGamesProto.SummerGamesProjectTemp.newBuilder();
            builder.setId(projectInfo.getId());
            builder.addAllMedalsId(projectInfo.getMedalsId());
            builder.setProjectName(ServerLanguageMgr.getContent(projectInfo.getProjectName(), player.getLanguage()));
            builder.setVenuesId(projectInfo.getVenuesId());
            builder.setVenuesName(ServerLanguageMgr.getContent(projectInfo.getVenuesName(), player.getLanguage()));
            builder.setProjectName(ServerLanguageMgr.getContent(projectInfo.getProjectName(), player.getLanguage()));
            builder.setProjectDesc(ServerLanguageMgr.getContent(projectInfo.getProjectDesc(), player.getLanguage()));
            clientMsg.addProject(builder);
        }

        for (SummerGamesConvertInfo convertInfo : summerGamesConfig.getConvertInfoList()) {
            SummerGamesProto.SummerGameConvertTemp.Builder builder = SummerGamesProto.SummerGameConvertTemp.newBuilder();
            builder.setId(convertInfo.getId());
            builder.setVenuesId(convertInfo.getVenuesId());
            builder.setExchangeReward(convertInfo.getExchangeReward());
            builder.addAllExchangeItem(convertInfo.getExchangeItemList());
            builder.setNumLimit(convertInfo.getNumLimit());
            builder.setType(convertInfo.getType());
            builder.setFlexiExchangeReward(convertInfo.getFlexiExchangeReward());
            clientMsg.addConvert(builder);
        }

        player.sendPacket(Protocol.U_SUMMER_GAMES_CONFIG_SYNC, clientMsg);

    }

    private void initUserData(SummerGamesConfig config) {
        // 系统未解锁
        if (!SystemOpenMgr.systemOpen(player, eSystemId.SummerGamesActivity.getValue())) {
            return;
        }

        // 没有活动
        if (!ActivityMgr.activityInShowTime(config.getActivityInfo()) || SummerGamesActivityMgr.getSummerGamesConfig() == null) {
            return;
        }

        ActivityInfo activityInfo = config.getActivityInfo();

        // 已经有数据了
        if (userData != null && userData.getActivityId() == activityInfo.getActivityId()) {
            return;
        }

        SummerGamesUserData tmpUserData = new SummerGamesUserData();

        tmpUserData.setActivityId(activityInfo.getActivityId());
        tmpUserData.setUserId(getUserId());
        tmpUserData.setDayGetGuessItemMap(new HashMap<>());
        tmpUserData.setMedalsMap(new HashMap<>());
        tmpUserData.setConvertNumMap(new HashMap<>());

        Map<Integer, SummerGamesLottery> poolDrawProcess = new HashMap<>();
        for (SummerGamesLotteryInfo lotteryInfo : config.getLotteryInfoList()) {
            SummerGamesLottery draw = new SummerGamesLottery();
            draw.setId(lotteryInfo.getId());
            if(null != lotteryInfo.getLeastNumMap() && lotteryInfo.getLeastNumMap().size() == 2){
                int result = random(random, lotteryInfo.getLeastNumMap());
                draw.setLn(result);
            }

            if(null != lotteryInfo.getNormalNumMap() && lotteryInfo.getNormalNumMap().size() == 2){
                int result = random(random, lotteryInfo.getNormalNumMap());
                draw.setMn(result);
            }

            if(tmpUserData.getDrawTimes() <= config.getFixNum()){
                if(lotteryInfo.getFixedNumMap().size() == 2){
                    int result = random(random, lotteryInfo.getFixedNumMap());
                    draw.setMn(result);
                }
            }

            poolDrawProcess.put(draw.getId(), draw);
        }
        tmpUserData.setPoolDrawProcess(poolDrawProcess);


        tmpUserData.setInsertOption();
        userData = tmpUserData;
    }

    private int random(Random random, List<Integer> weightList) {
        int min = weightList.get(0);
        int max = weightList.get(1);
        int result = max;
        if(max > min){
            result = min + random.nextInt(max - min + 1);
        }
        return result;
    }

    private boolean resetOneDay() {
        return false;
    }

    public void syncUserData() {
        if(userData != null){
            SummerGamesProto.SummerGamesUserDataSyncMsg.Builder clientMsg = SummerGamesProto.SummerGamesUserDataSyncMsg.newBuilder();
            SummerGamesProto.SummerGamesUserMainDataTemp.Builder builder = buildUserBuilder();
            clientMsg.setUserData(builder);

            SummerGamesProto.CrossSummerGamesUserLoginReqMsg.Builder crossMsg = SummerGamesProto.CrossSummerGamesUserLoginReqMsg.newBuilder();
            crossMsg.setActivityId(userData.getActivityId());
            crossMsg.setClientMsg(clientMsg);
            player.sendPacket(Protocol.C_SUMMER_GAMES_USER_LOGIN, crossMsg);
            //player.sendPacket(Protocol.U_SUMMER_GAMES_USER_SYNC, clientMsg);
        }
    }

    private SummerGamesProto.SummerGamesUserMainDataTemp.Builder buildUserBuilder() {
        if(userData != null){
            SummerGamesProto.SummerGamesUserMainDataTemp.Builder builder = SummerGamesProto.SummerGamesUserMainDataTemp.newBuilder();
            builder.setEntryScore(userData.getScore());
            builder.setEntryTimes(userData.getDrawTimes());

            for (Map.Entry<Integer, Integer> entry : userData.getMedalsMap().entrySet()) {
                SummerGamesProto.SummerGamesMedalsNumTemp.Builder innerBuilder = SummerGamesProto.SummerGamesMedalsNumTemp.newBuilder();
                innerBuilder.setMedals(entry.getKey());
                innerBuilder.setNum(entry.getValue());
                builder.addMedals(innerBuilder);
            }

            for (Map.Entry<Long, Integer> entry : userData.getDayGetGuessItemMap().entrySet()) {
                SummerGamesProto.SummerGamesGuessItemGetTemp.Builder innerBuilder = SummerGamesProto.SummerGamesGuessItemGetTemp.newBuilder();
                innerBuilder.setDayTime(entry.getKey());
                innerBuilder.setGet(true);
                builder.addGuessItemGet(innerBuilder);
            }

            for (Map.Entry<Integer, Integer> entry : userData.getConvertNumMap().entrySet()) {
                SummerGamesProto.SummerGamesConvertTimesTemp.Builder convertBuilder = SummerGamesProto.SummerGamesConvertTimesTemp.newBuilder();
                convertBuilder.setId(entry.getKey());
                convertBuilder.setNum(entry.getValue());
                builder.addConvertTimes(convertBuilder);
            }

            for (Map.Entry<Integer, SummerGamesSelectReward> entry : userData.getConvertSelectMap().entrySet()) {
                SummerGamesSelectReward value = entry.getValue();
                builder.addSelect(SummerGamesActivityMgr.buildSummerGamesSelectRewardTemp(value));
            }
            return builder;
        }
        return null;
    }

    public int entry(int type) {
        int times = 1;
        if(type == 1){
            times = 100;
        }
        if(userData == null){
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }

        SummerGamesConfig config = SummerGamesActivityMgr.getSummerGamesConfig();

        if(type == 1){
            if(userData.getDrawTimes() < config.getTenGachaLimit()){
                return GameErrorCode.E_SUMMER_GAMES_ENTRY_TEN_LIMIT;
            }
        }

        //判断道具是否足够
        long userBagItemCount = player.getModule(BagModule.class).getUserBagItemCount(config.getItemId());
        times = Math.min(times, (int)userBagItemCount);

        if(times <= 0){
            return GameErrorCode.E_BAG_ITEM_NO_ENOUGH;
        }

        //保底状态副本，防止异常造成脏数据
        HashMap<Integer, SummerGamesLottery> copyMemoryMap = copyHongXianMemoryHashMap(userData);

        RandomHelper randomHelper = new RandomHelper();
        boolean success = true;
        int curTimes = 0;

        List<SummerGamesLotteryInfo> lotteryInfoList = new ArrayList<>();
        List<SummerGamesProjectInfo> projectInfoList = new ArrayList<>();
        //临时配置，保证成套
        int SUMMERGAME_MEDALS_NUM_LIMIT = 1;
        //临时背包数量
        Map<Integer, Long> tempBagNumMap = new HashMap<>();
        BagModule module = player.getModule(BagModule.class);
        for (int i = 0; i < times; i++) {

            int projectIdIndex = random.nextInt(config.getProjectInfoList().size());
            SummerGamesProjectInfo projectInfo = config.getProjectInfoList().get(projectIdIndex);
            int totalTimes = userData.getDrawTimes() + i + 1;
            SummerGamesLotteryInfo get = drawOne(userData, config, copyMemoryMap, randomHelper, totalTimes);

            if(get == null){
                success = false;
                break;
            }

            //当前场馆
            int venuesId = projectInfo.getVenuesId();
            //如果获得奖牌
            if(get.getMedalsType() > 0){
                //均衡下奖牌
                Map<Integer, SummerGamesProjectInfo> sameMap = new HashMap<>();
                Map<Integer, Integer> medalsMap = new HashMap<>();
                for (SummerGamesProjectInfo info : config.getProjectInfoList()) {
                    if(venuesId == info.getVenuesId()){
                        sameMap.put(info.getId(), info);
                        medalsMap.put(info.getId(), info.getMedalsId().get(get.getMedalsType() - 1));
                    }
                }
                List<SummerGamesProjectInfo> poolList = new ArrayList<>();
                long min = Long.MAX_VALUE;
                for (Map.Entry<Integer, Integer> entry : medalsMap.entrySet()) {
                    int medalsId = entry.getValue();
                    long itemCount = module.getUserBagItemCount(medalsId) + tempBagNumMap.getOrDefault(medalsId, 0L);
                    if(min > itemCount){
                        min = itemCount;
                    }
                }
                for (Map.Entry<Integer, Integer> entry : medalsMap.entrySet()) {
                    int medalsId = entry.getValue();
                    long itemCount = module.getUserBagItemCount(medalsId) + tempBagNumMap.getOrDefault(medalsId, 0L);
                    if(itemCount - min < SUMMERGAME_MEDALS_NUM_LIMIT){
                        poolList.add(sameMap.get(entry.getKey()));
                    }
                }
                if(poolList.isEmpty()){
                    poolList.addAll(sameMap.values());
                }
                projectIdIndex = random.nextInt(poolList.size());
                projectInfo = poolList.get(projectIdIndex);
                Integer id = projectInfo.getMedalsId().get(get.getMedalsType() - 1);
                tempBagNumMap.put(id, 1 + tempBagNumMap.getOrDefault(id, 0L));
            }

            curTimes++;
            lotteryInfoList.add(get);
            projectInfoList.add(projectInfo);
        }

        if(curTimes <= 0){
            return GameErrorCode.E_GAME_ERROR;
        }

        if(!success){
            return GameErrorCode.E_GAME_ERROR;
        }

        //扣道具
        Property cost =  new Property();
        cost.addProperty(config.getItemId(), BigInteger.valueOf(curTimes));
        if(!player.getModule(CurrencyModule.class).removeCurrency(cost, eLogMoneyType.SummerGamesActivity, eLogMoneyType.SummerGamesActivityEntryConsume)){
            return GameErrorCode.E_BAG_ITEM_NO_ENOUGH;
        }

        //积分+奖牌
        int addScore = 0;
        Property reward = new Property();
        Map<Integer, Integer> medalsNumMap = new HashMap<>();
        Random random = new Random();
        for (int i = 0; i < projectInfoList.size(); i++) {
            SummerGamesProjectInfo projectInfo = projectInfoList.get(i);
            SummerGamesLotteryInfo lotteryInfo = lotteryInfoList.get(i);
            addScore += lotteryInfo.getScore();
            if(lotteryInfo.getMedalsType() > 0){
                Integer medalsId = projectInfo.getMedalsId().get(lotteryInfo.getMedalsType() - 1);
                reward.addProperty(medalsId, BigInteger.ONE);
                Integer num = medalsNumMap.getOrDefault(medalsId, 0);
                medalsNumMap.put(medalsId, num + 1);
            }
            //道具奖励
            reward.addProperty(RandomWeightConfigHelper.getProperty(config.getSUMMERGAME_ITEM_USE_REWARD(), random));
        }
        //没有积分道具奖励
//        reward.addProperty(config.getEXCHANGE_SCORE_ITEM_ID(), BigInteger.valueOf(addScore));

        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.SummerGamesActivity, eLogMoneyType.SummerGamesActivityEntryReward);
        userData.setScore(addScore + userData.getScore());
        userData.setDrawTimes(userData.getDrawTimes() + curTimes);
        for (Map.Entry<Integer, Integer> entry : medalsNumMap.entrySet()) {
            Integer num = userData.getMedalsMap().getOrDefault(entry.getKey(), 0);
            userData.getMedalsMap().put(entry.getKey(), num + entry.getValue());
        }
        userData.setPoolDrawProcess(copyMemoryMap);
        player.notifyListener(eGamePlayerEventType.SummerGamesEntryScoreRank.getValue(), userData.getScore());
        player.notifyListener(eGamePlayerEventType.SummerGamesEntryScoreArchive.getValue(), userData.getScore());

        SummerGamesProto.SummerGamesEntryRespMsg.Builder clientMsg = SummerGamesProto.SummerGamesEntryRespMsg.newBuilder();
        clientMsg.setRet(0);
        clientMsg.setAddScore(addScore);
        List<Map<String, Object>> logResultMap = new ArrayList<>();
        for (int i = 0; i < projectInfoList.size(); i++) {
            SummerGamesProjectInfo projectInfo = projectInfoList.get(i);
            SummerGamesLotteryInfo lotteryInfo = lotteryInfoList.get(i);
            SummerGamesProto.SummerGamesEntryResultTemp.Builder builder = SummerGamesProto.SummerGamesEntryResultTemp.newBuilder();
            builder.setVenuesId(projectInfo.getVenuesId());
            builder.setMedalsId(0);
            if(lotteryInfo.getMedalsType() > 0) {
                Integer integer = projectInfo.getMedalsId().get(lotteryInfo.getMedalsType() - 1);
                builder.setMedalsId(integer);
            }
            builder.setProjectId(projectInfo.getId());
            builder.setLotteryId(lotteryInfo.getId());
            clientMsg.addResult(builder);
            Map<String, Object> logResult = new HashMap<>();
            logResult.put("sub_id", projectInfo.getId());
            logResult.put("rak_id", lotteryInfo.getMedalsType());
            logResultMap.add(logResult);
        }
        reward.addProperty(config.getEXCHANGE_SCORE_ITEM_ID(), BigInteger.valueOf(addScore));
        clientMsg.setReward(PropertyHelper.parsePropertyToString(reward));
        player.sendPacket(Protocol.U_SUMMER_GAMES_ENTRY, clientMsg);

        //日志
        AutoLogMgr.add(new LogSummerGamesEntry(userData.getActivityId(), userData.getUserId(), times, logResultMap, addScore));

        syncUserData();
        return 0;
    }


    public void receiveSuccess(SummerGamesProto.SummerGamesExchangeInfoTemp info) {
        player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseGoodsToString(info.getNeedId(), BigInteger.ONE), eLogMoneyType.SummerGamesActivity, eLogMoneyType.SummerGamesActivityExchangeReward);
        SummerGamesExchangeTip tip = new SummerGamesExchangeTip(info.getId(), info.getNeedId(), 1);
        userData.getExchangeTipMap().put(tip.getId(), tip);
        syncExchangeTip(userData);
    }

    private void syncExchangeTip(SummerGamesUserData userData) {
        if(userData == null){
            return;
        }
        if(userData.getExchangeTipMap().isEmpty()){
            return;
        }
        SummerGamesProto.SummerGamesExchangeTipSyncMsg.Builder sync = SummerGamesProto.SummerGamesExchangeTipSyncMsg.newBuilder();
        for (Map.Entry<Long, SummerGamesExchangeTip> entry : userData.getExchangeTipMap().entrySet()) {
            SummerGamesExchangeTip tip = entry.getValue();
            SummerGamesProto.SummerGamesExchangeTipTemp.Builder builder = SummerGamesProto.SummerGamesExchangeTipTemp.newBuilder();
            builder.setId(tip.getId());
            builder.setMedalsId(tip.getGet());
            builder.setType(tip.getType());
            sync.addTip(builder);
        }
        player.sendPacket(ClientProtocol.U_SUMMER_GAMES_TIP_SYNC, sync);
    }

    public void receiveFail(List<SummerGamesProto.SummerGamesExchangeInfoTemp> infoList) {
        if(userData == null){
            return;
        }
        Property reward = new Property();
        for (SummerGamesProto.SummerGamesExchangeInfoTemp temp : infoList) {
            reward.addProperty(temp.getProvideId(), BigInteger.ONE);

            SummerGamesExchangeTip tip = new SummerGamesExchangeTip(temp.getId(), temp.getProvideId(), 2);
            userData.getExchangeTipMap().put(tip.getId(), tip);
        }
        userData.setUpdateOption();
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.SummerGamesActivity, eLogMoneyType.SummerGamesActivityExchangeRefuseBack);

        syncExchangeTip(userData);
    }

    public int readTip(List<Long> idList) {
        if(userData == null){
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        for (Long id : idList) {
            userData.getExchangeTipMap().remove(id);
        }
        userData.setUpdateOption();
        SummerGamesProto.SummerGamesExchangeTipReadRespMsg.Builder clientMsg = SummerGamesProto.SummerGamesExchangeTipReadRespMsg.newBuilder();
        clientMsg.setRet(0);
        for (Map.Entry<Long, SummerGamesExchangeTip> entry : userData.getExchangeTipMap().entrySet()) {
            SummerGamesExchangeTip tip = entry.getValue();
            SummerGamesProto.SummerGamesExchangeTipTemp.Builder builder = SummerGamesProto.SummerGamesExchangeTipTemp.newBuilder();
            builder.setId(tip.getId());
            builder.setMedalsId(tip.getGet());
            builder.setType(tip.getType());
            clientMsg.addTip(builder);
        }
        player.sendPacket(Protocol.U_SUMMER_GAMES_TIP_READ, clientMsg);
        return 0;
    }

    private SummerGamesLotteryInfo drawOne(SummerGamesUserData userData, SummerGamesConfig config, HashMap<Integer, SummerGamesLottery> copyMemoryMap, RandomHelper randomHelper, int totalTimes) {
        SummerGamesLotteryInfo get = null;

        //防欧的臻
        List<SummerGamesLotteryInfo> excludeList = new ArrayList<>();

        for (SummerGamesLotteryInfo lotteryInfo : config.getLotteryInfoList()) {

            SummerGamesLottery memory = copyMemoryMap.get(lotteryInfo.getId());
            //防欧,未到
            if(memory.getLn() > 0 && memory.getTimes() < memory.getLn()){
                excludeList.add(lotteryInfo);
                continue;
            }
            //是否到达保底
            if(memory.getMn() > 0 && memory.getTimes() + 1 >= memory.getMn()){
                get = lotteryInfo;
                break;
            }
        }

        if(get == null){
            List<Integer> weightOneList = new ArrayList<>();
            List<SummerGamesLotteryInfo> oneList = new ArrayList<>();
            //按概率来
            for (SummerGamesLotteryInfo lotteryInfo : config.getLotteryInfoList()) {
                if(excludeList.contains(lotteryInfo)){
                    continue;
                }
                oneList.add(lotteryInfo);

                if(totalTimes <= config.getFixNum()){
                    weightOneList.add(lotteryInfo.getFixedWeight());
                }else {
                    weightOneList.add(lotteryInfo.getWeight());
                }
            }
            int index = randomHelper.getSafeRandomIndexByWeight(weightOneList);
            get = oneList.get(index);
        }

        if(get == null){
            return null;
        }

        //重置保底
        SummerGamesLottery memory = copyMemoryMap.get(get.getId());
        memory.setTimes(0);

        SummerGamesLotteryInfo memoryInfo = config.getSummerGamesLotteryInfo(get.getId());
        if(memoryInfo.getNormalNumMap().size() > 0) {
            memory.setMn(random(random, memoryInfo.getNormalNumMap()));
        }
        if(totalTimes < config.getFixNum() && memoryInfo.getFixedNumMap().size() == 2){
            memory.setMn(random(random, memoryInfo.getFixedNumMap()));
        }
        if(memoryInfo.getLeastNumMap().size() > 0) {
            memory.setLn(random(random, memoryInfo.getLeastNumMap()));
        }

        //累加进度和次数
        for (Map.Entry<Integer, SummerGamesLottery> entry : copyMemoryMap.entrySet()) {
            SummerGamesLottery value = entry.getValue();
            if(value.getId() == get.getId()){
                continue;
            }
            value.setTimes(value.getTimes() + 1);
        }

        return get;
    }

    public SummerGamesUserData getUserData() {
        return userData;
    }

    private HashMap<Integer, SummerGamesLottery> copyHongXianMemoryHashMap(SummerGamesUserData userData) {
        HashMap<Integer, SummerGamesLottery> copyMemoryMap = new HashMap<>();
        for (Map.Entry<Integer, SummerGamesLottery> entry : userData.getPoolDrawProcess().entrySet()) {
            SummerGamesLottery value = entry.getValue();
            copyMemoryMap.put(entry.getKey(), value.clone());
        }
        return copyMemoryMap;
    }
}
